/**
 * Created by zd.
 */
import * as types from '../actions/ActionTypes';

function sessionStoragePut(key,value){
    //将对象转化成json字符串，存入sessionStorage
    localStorage.setItem(key, JSON.stringify(value));
}
function sessionStorageGet(key,isRemove){
    //从sessionStorage中取出json字符串，然后将json字符串转化成对象,并返回.
    var result=JSON.parse(localStorage.getItem(key));
    if(isRemove){
        localStorage.removeItem(key);
    }
    return result;
}
const app = (state = {}, action) => {
  switch (action.type) {
    case types.USER_LOGINED:
    sessionStoragePut('user',$.extend({},state,{user_logined:action.getData,userId:action.userId,userTel:action.userTel}));
    return $.extend({},state,{user_logined:action.getData,userId:action.userId,userTel:action.userTel});
    case types.FETCH_MALL_THEM_HOS_SERVITEM_DET:
    sessionStoragePut('user',$.extend({},state,{mall_them_hos_servItem_det:action.getData}));
    return $.extend({},state,{mall_them_hos_servItem_det:action.getData})
    case types.GET_ORDER_DETAIL:
    return $.extend({},state,{order_detail:action.getData})
    case types.USER_SHOP_LIST:
    state.user_shop_list = [];
    return $.extend({},state,{user_shop_list:action.getData});
    case types.GET_ORDER_CLASSIFY:
    console.log(state.get_order_classify);
    sessionStoragePut('user',$.extend({},state,{get_order_classify:action.getData}));
    return $.extend({},state,{get_order_classify:action.getData});
    case types.GET_ORDER_CLASSIFY_MORE:
    let a = action.getData.concat(state.get_order_classify)
    console.log(a);
    return $.extend({},state,{get_order_classify:a});
    case types.CHECKED_ARR:
    sessionStoragePut('user',$.extend({},state,{checkedArr:action.getData}));
    return $.extend({},state,{checkedArr:action.getData});
    default:
      return state
  }
}
export default app
